﻿<%@ Control Language="C#" Inherits="Yuanlin.Business.NewsEditControl, Yuanlin.Business" AutoEventWireup="true" %>

<%@Register tagPrefix="ctrl" tagName="Editor" src="~/themes/default/skins/Skin-HtmlEditor.ascx" %>

<script type="text/javascript">
<!--
function GetCities()
{
    var parentCategoryID = document.getElementById('<%= provinceDropDownList.ClientID %>').value;
    if(parentCategoryID != null)
    {             
        AjaxMethod.GetAreaChildCategories('<%= ClientID %>', parentCategoryID,  GetCitiesCallBack);
    }
}
function GetTowns()
{
    var parentCategoryID = document.getElementById('<%= cityDropDownList.ClientID %>').value;
    if(parentCategoryID != null)
    {             
        AjaxMethod.GetAreaChildCategories('<%=ClientID %>', parentCategoryID,  GetTownsCallBack);
    }
}
function GetSmallTowns()
{
    var parentCategoryID = document.getElementById('<%= townDropDownList.ClientID %>').value;
    if(parentCategoryID != null)
    {             
        document.getElementById('<%= townHidden.ClientID %>').value = parentCategoryID;
        AjaxMethod.GetAreaChildCategories('<%=ClientID %>', parentCategoryID,  GetSmallTownsCallBack);
    }
}
function changeSmallTowns()
{
    var parentCategoryID = document.getElementById('<%= smallTownDropDownList.ClientID %>').value;
    if(parentCategoryID != null)
    {  
        document.getElementById('<%= smallTownHidden.ClientID %>').value = parentCategoryID;
    }
}
function GetCitiesCallBack(res)
{
    var ddl = document.getElementById('<%= cityDropDownList.ClientID %>');
    ClearOptions(ddl);
 
    if(res.value == null || res.value == "")
    {
        return;
    }   
    var categories = res.value.split(";");
    for(var i = 0; i < categories.length; i++) { 
        var category = categories[i].split(":");
        var newOption=new Option(category[1],category[0]);
        ddl.options.add(newOption); 
    }  

    if(ddl.length > 0)
    {
        ddl.selectedIndex = 0;
        GetTowns(); 
    }
    
}
function GetTownsCallBack(res)
{
    var ddl = document.getElementById('<%= townDropDownList.ClientID %>');
    ClearOptions(ddl);
 
    if(res.value == null || res.value == "")
    {
        return;
    }   
    var categories = res.value.split(";");
    for(var i = 0; i < categories.length; i++) { 
        var category = categories[i].split(":");
        var newOption=new Option(category[1],category[0]);
        ddl.options.add(newOption); 
    }  

    if(ddl.length > 0)
    {
        ddl.selectedIndex = 0; 
        GetSmallTowns();
    }
}
function GetSmallTownsCallBack(res)
{
    var ddl = document.getElementById('<%= smallTownDropDownList.ClientID %>');
    ClearOptions(ddl);
 
    if(res.value == null || res.value == "")
    {
        return;
    }   
    var categories = res.value.split(";");
    for(var i = 0; i < categories.length; i++) { 
        var category = categories[i].split(":");
        var newOption=new Option(category[1],category[0]);
        ddl.options.add(newOption); 
    }  

    if(ddl.length > 0)
    {
        ddl.selectedIndex = 0; 
        changeSmallTowns();
    }
}
function ClearOptions(list) 
{ 
    while (list.options.length > 0) 
    { 
        list.options[0] = null; 
    } 
}
function CheckValue()
    {
        var select = document.getElementById('<%= parentNewsCategoryDropDownList.ClientID %>');
        var hasSelected = false;
        for(var i = 0; i < select.length; i++)
        {   
            if(select[i].selected)
            {
                hasSelected = true;
                break;
            }   
        }   
        if(hasSelected == false)
        {   
            alert('请选择类别！');
            select.focus();
            return false;
        }  

        select = document.getElementById('<%= childNewsCategoryDropDownList.ClientID %>');
        hasSelected = false;
        for(var i = 0; i < select.length; i++)
        {   
            if(select[i].selected)
            {
                hasSelected = true;
                break;
            }   
        }   
        if(hasSelected == false)
        {   
            alert('请选择子类别！');
            select.focus();
            return false;
        }
        
        var title = document.getElementById('<%= titleValuedTextBox.ClientID %>');
        if(title.value.length==0)
        {
            alert('请填写标题！');
            title.focus();
            return false;
        }
        
        var companyTypesCheckBoxList =  document.getElementById('<%= companyTypesCheckBoxList.ClientID %>');
        var chked=false;  
        var checks = companyTypesCheckBoxList.getElementsByTagName("input"); 
        var ichecked = 0;
        for(var n=0;n <checks.length;n++) 
        { 
            if(checks[n].type== "checkbox" && checks[n].checked==true) 
            { 
               chked=true; 
               ichecked=ichecked+1;
            } 
        } 
        if(!chked)
        {
            alert('请选择企业类型！');
            return false;
        } 
        
        var provinceDropDownList =  document.getElementById('<%= provinceDropDownList.ClientID %>');
        var cityDropDownList =  document.getElementById('<%= cityDropDownList.ClientID %>');
        var townDropDownList =  document.getElementById('<%= townDropDownList.ClientID %>');
        var smallTownDropDownList =  document.getElementById('<%= smallTownDropDownList.ClientID %>');
        if(provinceDropDownList.selectedIndex == "-1")
        {
            alert('请选择所在地区！');
            provinceDropDownList.focus();
            return false;
        } 
        if(cityDropDownList.selectedIndex == "-1")
        {
            alert('请选择所在地区！');
            cityDropDownList.focus();
            return false;
        }
        if(townDropDownList.selectedIndex == "-1")
        {
            alert('请选择所在地区！');
            cityDropDownList.focus();
            return false;
        }
        if(smallTownDropDownList.selectedIndex == "-1")
        {
            alert('请选择所在地区！');
            cityDropDownList.focus();
            return false;
        }
    
        return true;
    }
    function GetChildCategories()
    {
        var parentCategoryID = document.getElementById('<%= parentNewsCategoryDropDownList.ClientID %>').value;
        if(parentCategoryID != null)
        {             
	        AjaxMethod.GetChildCategories('<%=ClientID %>', parentCategoryID,  GetChildCategoriesCallBack);
        }
    }
    function GetChildCategoriesCallBack(res)
    {
        var childNewsCategoryValuedDropDownList = document.getElementById('<%= childNewsCategoryDropDownList.ClientID %>');
        ClearOptions(childNewsCategoryValuedDropDownList);
     
        if(res.value == null || res.value == "")
        {
            return;
        }   
        var categories = res.value.split(";");
        for(var i = 0; i < categories.length; i++) { 
            var category = categories[i].split(":");
            var newOption=new Option(category[1],category[0]);
            childNewsCategoryValuedDropDownList.options.add(newOption); 
        }  

        if(childNewsCategoryValuedDropDownList.length > 0)
        {
            childNewsCategoryValuedDropDownList.selectedIndex = 0; 
        }
    }
    
    function ClearOptions(list) 
    { 
        while (list.options.length > 0) 
        { 
            list.options[0] = null; 
        } 
    }
//-->
</script>
<asp:HiddenField ID="townHidden" runat="server" />
<asp:HiddenField ID="smallTownHidden" runat="server" />
<div class="AdminArea">
    <fieldset>
        <legend><nwap:ResourceLiteral runat="server" ResourceName="System_Applications_Yuanlin_EditNews" ResourceFile="ControlPanelResources.xml"></nwap:ResourceLiteral></legend>
		
		<div class="ThubnailImage">
			<nwap:YuanlinImage ID="yuanlinImage" runat="server" UseRealSize="true" ImageType="Details" Width="225" Height="225" PictureLink="true" DefaultFileName="defaultSiteSmallPic.gif" AttachmentName="News"/>
        </div>
        
        <div class="FormRow">
            <div class="LargerFieldNameRequireCharacter">
                <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml" ResourceName="RequireCharacter" />
                <nwap:ResourceLabel runat="Server" ControlToLabel="titleValuedTextBox" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_News_Title" />
            </div>
            <nwap:ValuedTextBox Runat="server" CssClass="InputField MiddleWidth" id="titleValuedTextBox" />
        </div>
        <div class="FormRow">
            <nwap:ResourceLabel ID="ResourceLabel3" CssClass="FieldName" runat="Server" ControlToLabel="attachmentData" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_Product_Picture" />
            <asp:FileUpload onchange="CheckImage(this)" Runat="server" CssClass="InputField MiddleWidth" id="attachmentData" />
        </div>
        <div class="FormRow">
            <div class="LargerFieldNameRequireCharacter">
                <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml" ResourceName="RequireCharacter" />
                <nwap:ResourceLabel runat="Server" ControlToLabel="parentNewsCategoryDropDownList" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_News_NewsClass" />
            </div>
            <nwap:ValuedDropDownList Runat="server" CssClass="InputField SmallWidth" onchange="GetChildCategories()" id="parentNewsCategoryDropDownList" />&nbsp;&nbsp;
            <nwap:ValuedDropDownList Runat="server" CssClass="InputField SmallWidth" id="childNewsCategoryDropDownList" />
        </div>
         <div class="FormRow">
            <div class="LargerFieldNameRequireCharacter">
                <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml" ResourceName="RequireCharacter" />
                <nwap:ResourceLabel runat="Server" ControlToLabel="companyTypesCheckBoxList" ResourceFile="ControlPanelResources.xml" ResourceName="EditProfile_CompanyType" />
            </div>
            <asp:CheckBoxList Runat="server" CssClass="CategoryCheckboxList" RepeatDirection="Horizontal" RepeatColumns="5" id="companyTypesCheckBoxList" />
        </div>   
       	<div class="FormRow">
            <div class="LargerFieldNameRequireCharacter">
                <nwap:ResourceLabel ID="ResourceLabel1" runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml" ResourceName="RequireCharacter" />
                <nwap:ResourceLabel ID="ResourceLabel2" runat="Server" ControlToLabel="provinceDropDownList" ResourceFile="ControlPanelResources.xml" ResourceName="EditProfile_UserArea" />
            </div>
            <nwap:ValuedDropDownList Runat="server" CssClass="InputField MicroWidth" onchange="GetCities()" id="provinceDropDownList" />
            &nbsp;&nbsp;<nwap:ValuedDropDownList Runat="server" CssClass="InputField MicroWidth" onchange="GetTowns()" id="cityDropDownList" />
            &nbsp;&nbsp;<nwap:ValuedDropDownList Runat="server" CssClass="InputField MicroWidth" onchange="GetSmallTowns()" id="townDropDownList" />
            &nbsp;&nbsp;<nwap:ValuedDropDownList Runat="server" CssClass="InputField MicroWidth" onchange="changeSmallTowns()" id="smallTownDropDownList" />
        </div>
        <div class="FormRow">
            <nwap:ResourceLabel CssClass="FieldName" runat="Server" ControlToLabel="topCheckBox" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_News_Top" />
            <asp:CheckBox ID="topCheckBox" runat="server" ToolTip="当前类别下置顶"/>
        </div>
        <div class="FormRow">
            <nwap:ResourceLabel CssClass="FieldName" runat="Server" ControlToLabel="bodyValuedEditor" ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_News_Body" />
            <br /><br /><ctrl:Editor Runat="server" Width="100%" Height="250px" id="descriptionValuedEditor" />
        </div>


        <div class="FormRow SubmitButtonRow">
            <nwap:Resourcebutton id="SaveButton" ResourceName="Save" CssClass="Button" Runat="server" OnClientClick="return CheckValue()"></nwap:Resourcebutton>&nbsp;&nbsp;&nbsp;&nbsp;
            <nwap:Resourcebutton id="BackButton" ResourceName="Back" CssClass="Button" Runat="server"></nwap:Resourcebutton>
        </div>	
    </fieldset>
</div> 